# encoding:utf8
'''
db :mongodb || redis
'''

import os
import tornado.ioloop
import tornado.web

from py_ex.log_ex import Dlog
####################SERVER######################

class Server(tornado.web.Application):
    '''服务器基类'''

    def __init__(self, handlers=None, settings=None, ui_modules=None):
        if not settings:
            settings = dict(static_path=os.path.join(os.getcwd(
            ), "static"), static_url_prefix="/static/", cookie_secret="todo", ui_modules=ui_modules)
        super(Server, self).__init__(handlers, debug=True, **settings)
        for handler in handlers:
            Dlog.i("\tHandle url--->>> {name}".format(name=handler[0]))

    def run(self, port):
        '''启动服务器'''
        self.listen(port)
        Dlog.i("Run on port %d..." % port)
        tornado.ioloop.IOLoop.instance().start()
